// Class for characters with animations
//
// Nick Kitten
// 2009

#include "Character.h"

using namespace std;


Character::Character( char * fileName, int id ) : Display3DObj( fileName, id )
{
	//Animation animations[ maxAnimations ];
	speed = 0;
}

Character::~Character()
{
}

void Character::addAnimation( Action action, char * fileName, int speed, 
		bool loopable, bool velocityDependent )
{
	Animation newAnim;
	newAnim.startFrame = dbTotalObjectFrames( this->getID() ) + 1;
	dbAppendObject( fileName, this->getID(), newAnim.startFrame );
	newAnim.duration = dbTotalObjectFrames( this->getID() ) - newAnim.startFrame;
	newAnim.speed = speed;
	newAnim.loopable = loopable;
	newAnim.velocDependent = velocityDependent;
	this->animations[action] = newAnim;
}

void Character::playAnimation( Action action )
{
	const Animation & anim = this->animations[action];
	int id = this->getID();
	//this->stopAnimation();
	dbSetObjectFrame( id, anim.startFrame );

	// need to also check for velocity-dependent speed later on
	dbSetObjectSpeed( id, anim.speed );

	if( anim.loopable )
	{
		dbLoopObject( id, anim.startFrame, anim.startFrame + anim.duration );
	}
	else
	{
		dbPlayObject( id, anim.startFrame, anim.startFrame + anim.duration );
	}
}

void Character::stopAnimation()
{
	dbStopObject( this->getID() );
}

// between 1-100, inclusive - changes how quickly transitions
// between animations occur
void Character::setInterpolation( int interp )
{
	dbSetObjectInterpolation( this->getID(), interp );
}
